package com.xiaoxin.suma.fragment;


import android.content.Context;
import android.support.v4.app.Fragment;

import com.xiaoxin.suma.utils.DataManger;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;
import rx.subscriptions.Subscriptions;

/**
 * Created by ljm on 2017/5/24.
 */

public class BaseFragment extends Fragment {

    protected Context mContext;
    protected String userName;
    protected String Token;
    protected CompositeSubscription subscriptions = Subscriptions.from();

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;
        initData();
        initView();
    }

    protected void initData() {
        Token = DataManger.getToken();
        userName = DataManger.getUserName();
    }

    protected void initView() {

    }

    protected void addSubscription(Subscription subscription) {
        subscriptions.add(subscription);
    }

    @Override
    public void onDestroy() {
        if (subscriptions != null && !subscriptions.isUnsubscribed()) {
            subscriptions.unsubscribe();
        }
        super.onDestroy();
    }
}
